package com.yonyou.cyxdms.sysAuth.service.controller.dealer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.sysAuth.service.dto.dealer.MsgTemplateDTO;
import com.yonyou.cyxdms.sysAuth.service.service.dealerchannel.MsgTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author duxiaoguang
 * @since 2019-09-04
 */
@Api(value = "通知模板", tags = {"通知模板"})
@RestController
@RequestMapping("/dealer/msgTemplate")
public class MsgTemplateController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(MsgTemplateController.class);

    @Autowired
    public MsgTemplateService msgTemplateService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author duxiaoguang
     * @since 2019-09-04
     */

    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "分页查询通知模板列表")
    public IPage<Map<String, Object>> getList(Map<String, Object> queryCondition, @RequestParam
            ("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        return msgTemplateService.selectPageBysql(page, queryCondition);
    }

    @PostMapping("/getTempCode")
    @ApiOperation(value = "根据Code查询通知模板")
    public MsgTemplateDTO getCode(@RequestParam("templateCode") Integer templateCode,
                                    @RequestParam("appId") String appId) {
        return msgTemplateService.selectTempInfo(templateCode,appId);
    }

    /**
     * 进行数据修改
     *
     * @param id 数据主键ID
     * @return Map<String   ,       Object> 数据对应的map 结构
     * @author duxiaoguang
     * @since 2019-09-04
     */
   /* @GetMapping(value = "/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "通知模板修改")
    public Map<String, Object> getById(@PathVariable("id") Integer id) {
        return msgTemplateService.getById(id);
    }*/

    /**
     * 进行数据新增
     *
     * @param msgTemplateDTO 需要保存的DTO
     * @return Map<String   ,       Object> 返回的数据map
     * @author duxiaoguang
     * @since 2019-09-04
     */
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "通知模板新增")
    public Map<String, Object> insert(@RequestBody MsgTemplateDTO msgTemplateDTO) {
        logger.debug("msgTemplateDTO:{}", msgTemplateDTO);
        return msgTemplateService.insert(msgTemplateDTO);
    }

    /**
     * 进行数据修改
     *
     * @param id             需要修改数据的ID
     * @param msgTemplateDTO 需要保存的DTO
     * @return Map<String   ,       Object> 返回的数据map
     * @author duxiaoguang
     * @since 2019-09-04
     */
/*    @PutMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "通知模板修改")
    public Map<String, Object> update(@PathVariable("id") Integer id, @RequestBody MsgTemplateDTO msgTemplateDTO) {
        logger.debug("msgTemplateDTO:{}", msgTemplateDTO);
        return msgTemplateService.update(id, msgTemplateDTO);
    }*/

    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author duxiaoguang
     * @since 2019-09-04
     */
//    @DeleteMapping
//    @ResponseStatus(HttpStatus.NO_CONTENT)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
//    })
//    @ApiOperation(value = "清空模板")
//    public boolean deleteById() {
//        msgTemplateService.deleteAll();
//        return true;
//    }

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author duxiaoguang
     * @since 2019-09-04
     */
/*    @DeleteMapping(value = "/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "批量删除")
    public boolean deleteByIds(@PathVariable("ids") String ids) {
        logger.debug("删除ID:{}", ids);
        msgTemplateService.deleteBatchIds(ids);
        return true;
    }*/


}